UltraDefrag User Manual

Written by Justin Dearing.
Modified by Dmitri Arkhangelski.

What is UltraDefrag?

UltraDefrag is an open source disk defragmenter for Windows NT 4.0 and later operating systems. It makes use of the same defragmenting API used by many other windows defrag utilities, both open and closed source. However, UltraDefrag has two features that make it unique. The first is that it has a kernel mode driver that does most of the work. The second is the ability to run the application at boot up time in a manner similar to chkdsk. This allows for faster defragmentation time and the ability to defragment all files including system files.

UltraDefrag supports the following filesystems FAT12/16/32, NTFS and on Vista UDF. UDF is a file system intended for optical media such as DVDs that unlike ISO9660, is rewriteable. It has also the ability to defragment volumes at boot time allowing you to move many system files that are always locked by the operating system. Currently all files besides the registry hives and the pagefile can be scanned at boot time. UltraDefrag can also defragment files and folders compressed by NTFS file system compression. And can even defragment floppies, although doing so is not particularly useful.

UltraDefrag binaries are available for the 32 bit and all 64 bit versions of Windows.

Installing UltraDefrag

You can download the latest installer for UltraDefrag at the project homepage (http://ultradefrag.sourceforge.net/). Simply download and run the installer. No reboot is required.

SOFTWARE REQUIREMENTS:

Note that you must be an administrator to install and run UltraDefrag.

If you have problems with configuration files editing, use the following menu in Explorer Tools > Folder options > File types and associate 'lua' and 'cfg' extensions with your preferred text editor.

Using UltraDefrag

IMPORTANT:

Console Application

The console application is called udefrag.exe. It is placed in system32 directory by the installer. Therefore you can call it from the command line or run box.

Command prompt
Microsoft Windows XP [5.1.2600] (C) Microsoft Corporation, 1985-2001. C:\>udefrag -a c:
UltraDefrag v1.4.1 console interface Copyright (c) Dmitri Arkhangelski, 2007,2008. Volume information: Volume size = 3.92 Gb Free space = 917.56 Mb Total number of files = 14688 Number of fragmented files = 126 Fragments per file = 1.21
C:\>_
Console Application after a successful analyze run.

The command line version takes a drive letter and one of the following switches:

To set defragger options you should use the Environment Variables. To set each of them you can simply type in command line set VarName=Value where VarName is a name of the environment variable and Value is a string to be assigned to the specified variable. The good practice is to store such commands in a batch script before udefrag.exe calls. That will save a lot of your time. This practice will be discussed below. Here is a list of defragmentation related environment variables with full explaination:

UD_IN_FILTER List of files to be included in defragmentation process. File names must be separated by semicolon. Most useful example is:
set UD_IN_FILTER=My Documents. After this assignment the defragger will process My Documents directory contents only.
The default value is an empty string that means: all files will be included.
UD_EX_FILTER List of files to be excluded from defragmentation process. File names must be separated by semicolon. Most useful example is:
set UD_EX_FILTER=system volume information;
temp;recycler
. After this assignment many temporary files will be excluded from the defragmentation process.
The default value is an empty string. It means: no files will be excluded.
UD_SIZELIMIT Ignore files larger than specified value. You can either specify size in bytes or use the following suffixes: Kb, Mb, Gb, Tb, Pb, Eb.
P.a., use set UD_SIZELIMIT=10Mb to exclude all files greater than 10 megabytes.
The default value is zero. It means: there is no size limit.
UD_REFRESH_INTERVAL Specify the progress indicator refresh interval in milliseconds.
The default value is 500.
UD_DISABLE_REPORTS Set this parameter to 1 (one) to disable reports generation.
The default value is 0.
UD_DBGPRINT_LEVEL This parameter can be in one of three states. Set UD_DBGPRINT_LEVEL=NORMAL to view useful messages about the analyse or defrag progress. Select DETAILED to create a bug report to send to the author when an error is encountered. Select PARANOID in extraordinary cases. Of course, you need have DbgView program or DbgPrint Logger installed to view logs.
The default value is NORMAL.

Notes about filter:

Specifying just the drive letter will cause UltraDefrag to defragment the drive. When the operation finishes or you stop the program with a Ctrl+C, the program will display the results to the console. If you abort the operation with Ctrl+C or close the shell window, UltraDefrag will exit safely without destroying any data.

The console application is also used as context menu handler. When you right click drive/folder/file icon in Explorer you can select [--- Ultra Defragmenter --] item to defragment selected file.

The best practice is to use the console application in batch scripts. You can define all program's options there and defragment multiple volumes in series by typing a single command. Here is the complete example. To try them store the code into ud-example.cmd file and click it's icon.

@echo off

set UD_EX_FILTER=system volume information;temp;recycler
set UD_SIZELIMIT=50Mb
udefrag c: > c:\ud.log

set UD_IN_FILTER=My Documents
udefrag d: >> c:\ud.log

set UD_IN_FILTER=
udefrag e: >> c:\ud.log

The command set UD_IN_FILTER= destroys the specified variable. The appropriate option will have the default value after this command.

Batch files are powerful enough, try to insert commands to play sounds after each defragmentation. If you doubt that your volumes are in good state then add chkdsk command too. Also you can use shutdown -s -t 00 command to halt your computer after the defragmentation job.

To get list of available volumes type udefrag -l. Each line of output contains volume letter, type of file system, total size and percent of free space. Here is an example:

Command prompt
Microsoft Windows XP [5.1.2600] (C) Microsoft Corporation, 1985-2001. C:\>udefrag -l
UltraDefrag v1.4.0 console interface Copyright (c) Dmitri Arkhangelski, 2007,2008.
Volumes available for defragmentation: C: NTFS 3.92 Gb 6 % D: NTFS 9.42 Gb 3 % E: FAT32 59.30 Gb 5 %
C:\>_

There are also few defragmentation related command line utilites:

boot-config - edit boot time defragmenter options
boot-off    - disable boot time defragmenter
boot-on     - enable boot time defragmenter
ud-config   - edit GUI options
ud-help     - show list of supported commands

Windows Application

The windows application is a simple application with one main form of fixed size and an about box. An illustration of the window as well as an explanation of their functionality is below:

Main window

  1. List of volumes. This list all drives on the machine that you can scan. CDROM's and other drives that cannot be defragmented are excluded from list automatically. If the 'Skip removable media' box is checked, also floppies and other similar devices will be excluded. This list has the following fields:

  2. Skip Removeable Media Checkbox

  3. Cluster Map This is a color coded representation of all drives. Here is colors explaination:

    Fragmented
    Unfragmented
    Free
    Directory
    Compressed
    System
    Temporary system
    MFT

    Some of the categories on the legend have a lighter and darker color on them. The lighter colors represent files below the file size threshold, and the darker colors represent files above the threshold if one is set. The cyan color represents space temporarily allocated by system.

  4. Rescan Drives (Ctrl+R) This button will recheck all volumes in the system to see if some were added or removed.

  5. Buttons
    The following section explains the buttons along with listing their shortcut keys.

  6. Progress bar This displays the progress of the currently running analyze, compact or defrag task. Note that selecting a different volume will cause this bar to disappear.

GUI executable since 2.0.0 version is contained in %windir%\system32\udefrag-gui.exe file.

To edit GUI startup commands click Main options button in Settings dialog or use the appropriate shortcut in Start Menu. The script udefrag-gui.cmd contains GUI startup commands, usually few set commands plus %windir%\system32\ultradefrag.exe command at the end to launch the UltraDefrag GUI Shell. To understand the contents of this script read please carefully the console application section of this document. The environment variables used here are the same. Here is an example of script, installed by default:

@echo off
rem ------------ UltraDefrag GUI startup commands -------------------
set UD_EX_FILTER=system volume information;temp;recycler
%windir%\system32\ultradefrag.exe
exit

The first command disables commands displaying in command prompt. Rem includes comment in script. Set sets list of files to be excluded from defragmentation process. The next command launches the UltraDefrag GUI Shell. Exit command is used to break script execution.

Boot time scan

UltraDefrag also includes a new mode that allows you to run it at boot time in a manner similar to chkdsk. This is known as a native application.

The only restriction on boot time scans is that you may not scan encrypted volumes. This is because lsass.exe, the component of the operating system that reads encrypted volumes, is loaded after the native executable runs.

The boot time defragmenter can be enabled by boot-on command typed in the command line. To disable them use the boot-off command. There are also the corresponding shortcuts in Start->Programs->UltraDefrag menu.

When the defrag_native.exe starts at boot time it interpretes the commands from the %windir%\system32\ud-boot-time.cmd file. To edit them type in command prompt boot-config or use the corresponding shortcut in Start menu.

The following commands are supported:

@echo onShow commands on the screen. This is the default behaviour.
@echo offDisable showing commands on the screen.
set Set specified environment variable. The usage is the same as described in console application section of this document.
udefrag This command has the same options as the console interface.
pausePause the script execution for the specified interval (in milliseconds). P.a. the command pause 1000 will pause execution for one second.
shutdownHalt the computer.
rebootReboot the computer.
exitBreak the boot time program execution.

The strings with a semicolon (;) or # characters in the beginning are comments.

Here is the complete example, installed by default:

;--------------------------------------------------------------------
;                UltraDefrag Boot Time Shell Script
;--------------------------------------------------------------------
; !!! NOTE: THIS FILE MUST BE SAVED IN UNICODE (UTF-16) ENCODING !!!
;--------------------------------------------------------------------

set UD_IN_FILTER=windows;winnt;ntuser;pagefile;hiberfil
set UD_EX_FILTER=temp

udefrag c:

exit

Note: If there is no exit command specified, the program will run in interactive mode after the last script command execution. To show list of supported commands type help. To continue the Windows Boot Process type exit.

Hack: If you are using Windows 98 operating system but you wish to use the UltraDefragmenter to optimize your drives from time to time than you have now one cool solution for that. Install Windows XP as a second operating system, install UltraDefrag on them and enable the boot time defragmenter. Insert the reboot command in the boot time script and enjoy! You can simply boot Windows XP, it will defrag anything and automatically reboot the computer at the end.

The Report

Everytime you run analyze, compact or defragment, a report of all fragmented files on the file system is created. Objects excluded from the defragmentation process are marked by black color. The report has the following fields:

  1. Number of fragments.
  2. Filename
  3. Comment - can be blank or contain one of three values:

To change items sorting click top link on the preferred column. Note that it's a slow process - about 1.5 seconds for 550 items on 1.8GHz CPU. Sorting implemented in JavaScript is slow, but very reliable.

Scheduling Defrag runs.

The command line version of UltraDefrag may be run out of system scheduled tasks. The process of adding a scheduled task instance of UltraDefrag is simplified throuth a utility called UltraDefrag Scheduler.NET. This small application requires Microsoft .NET Framework 2.0 to run. The simple gui has 4 settings.

UltraDefrag Scheduler.NET

  1. Whether to run Ultra Defrag every day (Daily) or only certain days of the week (Weekly).
  2. The time of day to run the task.
  3. The drive letter to scan.
  4. Days of the week to defrag if Weekly is selected.

Portable UltraDefrag

Portable package was made especially for people who wants to launch UltraDefrag from USB-flash without an installation. If you have selected a portable app to be installed, the installer will write all needed files into one directory on your hard drive. To get access to that directory use shortcut
Start -> Programs -> UltraDefrag -> Portable package. Or find it manually in %windir%\UltraDefrag. Place all files contained there on any removable media, p.a. on your USB-flash. Than you can run UltraDefrag on any compatible computer without an installation. Here is more information about portable applications.

There is one configuration file used by portable application. Here you can specify some options, most useful is a language definition. The file has a PORTABLE.X name. The complete example is here:

[Bootsplash]
Show=1
[i18n]
Language=Hungarian

Set Show=0 in the [Bootsplash] section to disable bootsplash on startup.

Set Language=LanguageName to choose your preferred language to be used by portable GUI. Available languages are: Catala, Chinese (Simplified), Chinese (Traditional), Dutch, English (US), French (FR), German, Greek, Hungarian, Italian, Portuguese, Russian, Slovak, Slovenian.

UltraDefrag Micro Edition

The UltraDefrag Micro Edition is a special package for advanced users who prefers extreme stability and power. This edition is a little bit faster, much stable (it's driver contains just most important parts). It has only console interface to speed up defragmentation process. Boot-time feature is available too. The Micro Edition saves reports in plain text format. You can find them in x:\fraglist.txt file (x = drive letter).

Note that console interface is very powerful, it has a full set of commands to perform any disk defragmentation job. To show full list of UltraDefrag related commands type ud-help.

Configuration files

Report options

They are stored in udreportopts.lua file located in %windir%\UltraDefrag\options directory. This is just a simple text file (in ANSI encoding) with comments and parameter-value pairs. However it's a real program written in Lua language.

The strings with -- character sequence in the beginning are comments. Here is a complete example:

--------------------------------------------------------------------
-- Ultra Defragmenter report options
--------------------------------------------------------------------

--------------------------------------------------------------------
-- I. Output Formats
--------------------------------------------------------------------
produce_html = 1

--------------------------------------------------------------------
-- II. HTML specific options
--------------------------------------------------------------------

--------------------------------------------------------------------
-- Generally ASCII renders better in Internet Explorer and 
-- UTF-16 renders better in FireFox. UTF-16 is of course required
-- to properly render Asian characters such as Japanese and Chinese.
--------------------------------------------------------------------
use_utf16 = 0

--------------------------------------------------------------------
-- Set enable_sorting to zero if your web browser is too old
-- and you have error messages about ivalid javascript code.
--------------------------------------------------------------------
enable_sorting = 1

--------------------------------------------------------------------
-- Set this parameter to 1 if you prefer to look at filenames 
-- splitted into few short lines. If you prefer to use fullscreen 
-- mode of your web browser then set this parameter to zero.
--------------------------------------------------------------------
split_long_names = 1
--------------------------------------------------------------------
-- Set here maximum number of characters per line 
-- in filename cells.
--------------------------------------------------------------------
max_chars_per_line = 50

--------------------------------------------------------------------
-- This stylesheet is used to set styles for various 
-- report elements.
--------------------------------------------------------------------
style = [[
<style>
td {font-family: monospace; font-size: 10pt}
.c {text-align: center}
.f {background-color: #000000; color: #FFFFFF}
</style>
]]

title_tags = {
	open = "<pre><h3>",
	close = "</h3></pre>"
}

--------------------------------------------------------------------
-- Main report table properties.
--------------------------------------------------------------------
table_style = [[
border="1" color="#FFAA55" cellspacing="0" width="100%"
]]

How it works

The actual work of moving files to different clusters is performed through the windows API. What makes UltraDefrag superior to the standard windows defrag utility is that it uses its own algorithm to determine where to place files. Also, the actual work is done by the kernel driver ultradfg.sys. This enhances performance because there is no constant switching between user mode and kernel mode.

Getting the Source

The latest sources for UltraDefrag is available via subversion.
The url is https://ultradefrag.svn.sourceforge.net/svnroot/. The program is written in C. The code is very clear and understandable. Detailed compilation instructions are located in INSTALL.TXT file in /src subdirectory of the source code.

Reporting Bugs

Please report all problems and bugs via the sourceforge bug tracker.

NOTE: Please include the following data in your bug report:

See Also


Powered by Lua Valid HTML 4.01 Transitional SourceForge.net Logo